package com.test.rabbitmq.direct;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.test.rabbitmq.BaseRunnable;
import com.test.rabbitmq.RabbitMQUtil;

public class Publisher extends BaseRunnable {

    private final static String EXCHANGE_NAME = "test_exchange_direct";

    @Override
    public void execute() throws Exception {
        // 获取到连接以及mq通道
        Connection connection = RabbitMQUtil.getConn("user", "user");
        Channel channel = connection.createChannel();
        // 声明exchange
        channel.exchangeDeclare(EXCHANGE_NAME, "direct");
        // 消息内容
        channel.basicPublish(EXCHANGE_NAME, "insert", null, "新增商品".getBytes());
        channel.basicPublish(EXCHANGE_NAME, "update", null, "更新商品".getBytes());
        channel.basicPublish(EXCHANGE_NAME, "delete", null, "删除商品".getBytes());
        System.out.println(" [x] Sent message.");
        channel.close();
        connection.close();
    }
}
